/*
测试upload.cgi是否

./gen.elf  100          data/D100B
./gen.elf  500          data/D500B
./gen.elf  1024         data/D1K
./gen.elf  1025         data/D1_1K
./gen.elf  4096         data/D4K
./gen.elf  4097         data/D4_1K
./gen.elf  8192         data/D8K
./gen.elf  8192.D1      data/8_1K
./gen.elf  1048576      data/D1M
./gen.elf  1048577      data/D1_1M
./gen.elf  8388608      data/D8M
./gen.elf  8388609      data/D8_1M


curl -F "file=@data/D100B"       http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D500B"       http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D1K"         http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D1_1K"       http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D4K"         http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D4_1K"       http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D8K"         http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/8_1K"        http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D1M"         http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D1_1M"       http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D8M"         http://192.168.1.249/cgi-bin/upload.cgi
curl -F "file=@data/D8_1M"       http://192.168.1.249/cgi-bin/upload.cgi



ls D* | xargs md5sum  | sort > /tmp/md.txt | md5sum /tmp/md.txt

*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void generate_file(const char *filename, size_t size) {
    FILE *file = fopen(filename, "w");
    if (!file) {
        perror("fopen");
        exit(EXIT_FAILURE);
    }

    char line[100];  // 99 '1's + 1 '\n'
    memset(line, '1', 99);
    line[99] = '\n';

    size_t written = 0;
    while (written + 100 <= size) {
        fwrite(line, 1, 100, file);
        written += 100;
    }

    // Handle the remaining bytes if any
    size_t remaining = size - written;
    if (remaining > 0) {
        if (remaining <= 99) {
            memset(line, '1', remaining);
            fwrite(line, 1, remaining, file);
        } else {
            memset(line, '1', 99);
            fwrite(line, 1, 99, file);
            fputc('\n', file);
        }
    }

    fclose(file);
}

int main(int argc, char **argv) {
    generate_file(argv[2], atoi(argv[1]));

    return 0;
}

